"use strict";
var sortColors = function (nums: number[]) {
    let left = 0;
    let right = nums.length - 1;
    const swap = (i: number, j: number) => {
        const t = nums[i];
        nums[i] = nums[j];
        nums[j] = t;
    };
    right = nums.length - 1;
    let p = 0;
    while (true) {
        while (nums[p] === 1) {
            p++;
        }

        if (p > right) break

        if (nums[p] === 0) {
            swap(left, p);
            left++;
            p++;
            continue
        }
        if (nums[p] === 2) {
            swap(right, p);
            right--;
        }
    }
    return nums;
};
console.log(sortColors([1, 1, 0, 0, 0, 0, 1, 1, 2, 1, 0, 2, 2]));
;
